package com.tnsw.facebookautoliker.helper;

import com.tnsw.coreutils.AsyncManager;
import com.tnsw.coreutils.MyLog;
import com.tnsw.coreutils.queuemanager.QM;
import com.tnsw.coreutils.queuemanager.QueueInfo;
import com.tnsw.coreutils.queuemanager.queueobjects.QiNetworkLog;

public class GeneralManager extends AsyncManager {

	protected String tag = "GeneralManager";
	private static boolean sIsRunning = false;
	private static GeneralManager sInstance;
	
	public GeneralManager() {
		super();
		super.logName = "GeneralManager";
		
		sInstance = this;
		sIsRunning = true;
	}
	
	public GeneralManager(int threadCount) {
		super(threadCount);
		super.logName = "GeneralManager";
		
		sInstance = this;
		sIsRunning = true;
		
	}
	
	@Override
	public void onNewQueueReceived(QM sender, QueueInfo qi) {
		super.onNewQueueReceived(sender, qi);
		
		if (!(qi.getObject() instanceof QiNetworkLog)) {
			MyLog.d(tag, "Received new queue: " + qi.getObject().getClass().getName());	
		}
		
		
		if (qi.getObject() instanceof FacebookCommandObject) {
			FacebookCommandObject fbco = (FacebookCommandObject) qi.getObject();
			FacebookBGManager fbm = FacebookBGManager.getInstance(null);
			fbm.execute(fbco);
		}
		
	}
	
	public static GeneralManager getInstance() {
		if (sIsRunning == false) {
			sInstance = new GeneralManager();
		}
		
		return(sInstance);
	}
}
